package com.intellagric.service.iftmonitor.Impl.ift_ctrl_equipment;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.IftCtrlEquipmentButtonMapper;
import com.intellagric.pojo.IftCtrlEquipmentButton;
import com.intellagric.pojo.IftCtrlEquipmentButtonExample;
import com.intellagric.service.iftmonitor.ift_ctrl_equipment.CtrlEquipmentButtonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/4/29
 * @DESC： 设备控制通道按钮管理服务
 */
@Service
public class CtrlEquipmentButtonServiceImpl implements CtrlEquipmentButtonService {

    @Autowired
    private IftCtrlEquipmentButtonMapper ctrlEquipmentButtonMapper;

    /**
     * 添加设备控制通道按钮
     * @param ctrlEquipmentButton
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addCtrlEquipmentButton(IftCtrlEquipmentButton ctrlEquipmentButton) {
        if (ctrlEquipmentButtonMapper.insertSelective(ctrlEquipmentButton) == 1 ) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除设备控制通道按钮
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteCtrlEquipmentButton(String id) {
        if (ctrlEquipmentButtonMapper.deleteByPrimaryKey(id) == 1 ) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除设备控制通道按钮
     * @param ctrlEquipmentButton
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editCtrlEquipmentButton(IftCtrlEquipmentButton ctrlEquipmentButton) {
        if (ctrlEquipmentButtonMapper.updateByPrimaryKeySelective(ctrlEquipmentButton) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }


    /**
     * 通过id查询按钮的详细信息
     *
     * @param id
     * @return ResponseMessage
     */
    @Override
    public IftCtrlEquipmentButton getCtrlEquipmentButtonById(String id) {
        return ctrlEquipmentButtonMapper.selectByPrimaryKey(id);
    }


    /**
     * 通过设备控制通道id查询按钮的列表
     * @param ctrlEquipmentButton
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentButtonListByVo(IftCtrlEquipmentButton ctrlEquipmentButton) {
        IftCtrlEquipmentButtonExample ctrlEquipmentButtonExample = new IftCtrlEquipmentButtonExample();
        ctrlEquipmentButtonExample.createCriteria().andRelIdEqualTo(ctrlEquipmentButton.getRelId());
        List<IftCtrlEquipmentButton> ctrlEquipmentButtonList = ctrlEquipmentButtonMapper.selectByExample(ctrlEquipmentButtonExample);
        return LayuiDataGridResult.success().add(ctrlEquipmentButtonList,ctrlEquipmentButtonList.size());
    }

    /**
     * 通控制设备id查询控制按钮列表
     *
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentButtonList(String ctrlEquipmentId) {
        IftCtrlEquipmentButtonExample ctrlEquipmentButtonExample = new IftCtrlEquipmentButtonExample();
        ctrlEquipmentButtonExample.createCriteria().andCtrlEquipmentIdEqualTo(ctrlEquipmentId);
        List<IftCtrlEquipmentButton> ctrlEquipmentButtonList = ctrlEquipmentButtonMapper.selectByExample(ctrlEquipmentButtonExample);
        return LayuiDataGridResult.success().add(ctrlEquipmentButtonList,ctrlEquipmentButtonList.size());
    }
}
